package com.yy.yyui.button
{
	import com.siku.manor.config.Sys;
	import com.siku.manor.view.common.UM;
	import com.siku.manor.view.component.GT;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class SpriteButton extends Sprite
	{
		private var w:Number,h:Number;
		private var overEffect:DisplayObject;
		private var _enabled:Boolean;
		private var _actions:Object;
		public function SpriteButton(dobj:DisplayObject)
		{
			//TODO: implement function
			super();
			w = dobj.width;
			h = dobj.height;
			
			overEffect =  UM.innerGlowYellowLight;
			overEffect.width = this.width;
			overEffect.height = this.height;
			overEffect.visible = false;
			_enabled = true;
			
			this.addChild(dobj);
			this.addChild(overEffect);
			this.buttonMode =  true;
			GT.enableMouseDownAlphaEffect(this);
			this.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler);
			this.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandler);
			this.addEventListener(MouseEvent.CLICK,mouseClickHandler);
			this._actions = {};
		}
		
		public function get onClick():Function{
			return this.actions.onClick;
		}
		public function set onClick(value:Function):void{
			this.actions.onClick = value;
		}
		
		private function mouseClickHandler(e:MouseEvent):void{
			this.onClick(e);
		}
		
		public function get actions():Object{
			return this._actions;
		}		
		public function get enable():Boolean{
			return _enabled;
		}
		
		public function set enable(value:Boolean):void{
			if(value){
				this.filters = null;
			}else{
				this.filters = Sys.BUTTON_DISABLE_FILTER;
			}
			_enabled = value;
		}
		
		private function mouseOverHandler(e:MouseEvent):void{
			if(this.enable){
				this.overEffect.visible = true;
			}
		}
		
		private function mouseOutHandler(e:MouseEvent):void{
			this.overEffect.visible =  false;
		}
		
		override public function get width():Number{
			return w;
		}
		
		override public function get height():Number{
			return h;
		}
		
		override public function set width(newWidth : Number) : void {
			var diff:Number = newWidth - w;
			w = newWidth;
		}
		
		override public function set height(newHeight : Number) : void {
			var diff:Number = newHeight - h;
			h = newHeight;			
		}		
	}
}